package pkg

import (
	"context"
	"github.com/qiniu/go-sdk/v7/storagev2/credentials"
	"github.com/qiniu/go-sdk/v7/storagev2/http_client"
	"github.com/qiniu/go-sdk/v7/storagev2/uploader"
	"mime/multipart"
)

func QiNiuYun(fileName string, file multipart.File) (string, error) {
	accessKey := "bq4PPJjuZ1P--8BX_MRZDuA_0O5t5GlTg72OEP0d"
	secretKey := "yL4Gf51B__zaSI5bcFtGWpveuGlzlKW2P_hvawpY"
	mac := credentials.NewCredentials(accessKey, secretKey)
	bucket := "2210ayangxiangyu"
	key := fileName
	uploadManager := uploader.NewUploadManager(&uploader.UploadManagerOptions{
		Options: http_client.Options{
			Credentials: mac,
		},
	})
	err := uploadManager.UploadReader(context.Background(), file, &uploader.ObjectOptions{
		BucketName: bucket,
		ObjectName: &key,
		FileName:   key,
		CustomVars: map[string]string{
			"name": "github logo",
		},
	}, nil)

	return "http://sos6ah016.hn-bkt.clouddn.com/" + key, err

}
